home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 616 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. From: kanze@gabi-soft.fr (J. Kanze)
  2. Message-ID: <KANZE.96Mar4120116@gabi.gabi-soft.fr>
  3. X-Original-Date: 04 Mar 1996 11:01:16 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 04 Mar 96 12:49:41 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: wchar_t version of atof() and atoi()?
  9. Organization: GABI Software, Sarl.
  10. References: <4h4oiv$4md@xanadu.io.com>
  11. In-Reply-To: jamshid@io.com's message of 29 Feb 1996 10:49:07 PST
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMTrm/uEDnX0m9pzZAQGxMgGAhYsWkXGc2VQtsQSbLaAjzlTiulfhsEfr
  14.     TiJHnfDrFTkGC5A6aAZoBctvqsl+mXtZ
  15.     =uCBn
  16.  
  17. In article <4h4oiv$4md@xanadu.io.com> jamshid@io.com (Jamshid Afshar)
  18. writes:
  19.  
  20. |> I'm new to internationalization issues but it's my understanding that
  21. |> Standard C++ will have very good support for it by way of the
  22. |> wide-character wstring and wifstream, etc. classes.  For example, a
  23. |> C++ program written in an environment that supports Unicode would
  24. |> strictly use wstring, wifstream, and wchar_t in place of string,
  25. |> ifstream, and char [1].  But, I didn't see a wchar_t* overload of
  26. |> functions like strtod() or atoi().  How are strings (eg, entered by a
  27. |> user into an edit box) supposed to be converted to numeric values in
  28. |> an internationalized C++ program?
  29.  
  30. Using a wchar_t version of istringstream, I suppose.  In general, very
  31. little has been done with regards to the various functions inherited
  32. from C that operated on char* or const char*; it is expected that most
  33. C++ programs will use string and iostream.
  34.  
  35. |> I would do something like:
  36.  
  37. |>     int atoi( const wstring& s ) {
  38. |>        wistringstream strm(s);
  39. |>        int r;
  40.  
  41. ===>    s.setf( ios::dec , ios::basefield) ;
  42.  
  43. |>        s >> r;
  44. |>        if (s) return r;
  45. |>        else throw some_exception();
  46. |>     }
  47.  
  48. |> But stream i/o interprets "045" as an octal value instead of 45.
  49.  
  50. Insert the specified line.  On creation, the basefield is 0, which has
  51. the behavior you describe.
  52.  
  53. -- 
  54. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  55. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  56. Conseils, itudes et rialisations en logiciel orienti objet --
  57.               -- A la recherche d'une activiti dans une region francophone
  58. ---
  59. [ To submit articles: try just posting with your news-reader.
  60.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  61.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  62.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  63.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  64. ]
  65.